/*
 * RendererEvents.cpp
 *
 *  Created on: Sep 4, 2011
 *      Author: Patrick
 */

#include "MediaCenter.h"
#include "Renderer.h"
#include "Repository.h"

extern "C" {
#include "video/Video.h"
}

void Renderer::captureEvents(SDL_Event* event) {

	switch (event->type) {
		case SDL_QUIT:
			this->stop();
			break;
		case SDL_KEYDOWN:
			this->context.keyBuffer[this->context.keyBufferIndex++] = event->key.keysym.sym;
			this->context.activeKeys[event->key.keysym.sym] = 1;
			break;
		case SDL_KEYUP:
			this->context.activeKeys[event->key.keysym.sym] = 0;
			break;
	}

}

void Renderer::processEvents() {

	if (this->context.keyBufferIndex > 0) {
		for (int i = 0; i < this->context.keyBufferIndex; i++) {
			switch (this->context.keyBuffer[i]) {
				case SDLK_ESCAPE:
					this->stop();
					break;
				case SDLK_F1:
					this->context.screenWidth = 1920;
					this->context.screenHeight = 1080;
					this->context.sdlVideoFlags ^= SDL_FULLSCREEN;
					SDL_SetVideoMode(this->context.screenWidth, this->context.screenHeight, 0, this->context.sdlVideoFlags);
					break;
				case SDLK_5:
					MCVideoSetPosition(0.5f);
					break;
				case SDLK_TAB:
					MCVideoCreate((char*)"b.mkv", 1280, 720);
					MCVideoPlay();
					break;
				case SDLK_SPACE:
					if (MCVideoIsPlaying()) {
						MCVideoPause();
					} else {
						MCVideoPlay();
					}
			}
		}
		this->context.keyBuffer = new int[64];
		this->context.keyBufferIndex = 0;
	}

}
